<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get the SQL of the statement</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="sqlite3stmt.execute.html">« SQLite3Stmt::execute</a></li>
      <li style="float: right;"><a href="sqlite3stmt.paramcount.html">SQLite3Stmt::paramCount »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.sqlite3stmt.html">SQLite3Stmt</a></li>
    <li>Get the SQL of the statement</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="sqlite3stmt.getsql" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3Stmt::getSQL</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.4.0, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3Stmt::getSQL</span> &mdash; <span class="dc-title">Get the SQL of the statement</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3stmt.getsql-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3Stmt::getSQL</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$expand</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Retrieves the SQL of the prepared statement. If <code class="parameter">expand</code>
   is <strong><code>false</code></strong>, the unmodified SQL is retrieved. If <code class="parameter">expand</code>
   is <strong><code>true</code></strong>, all query parameters are replaced with their bound values, or with
   an SQL <code class="literal">NULL</code>, if not already bound.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3stmt.getsql-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">expand</code></dt>

    <dd>

     <p class="para">
      Whether to retrieve the expanded SQL. Passing <strong><code>true</code></strong> is only supported as
      of libsqlite 3.14.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3stmt.getsql-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the SQL of the prepared statement,  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-sqlite3stmt.getsql-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   If <code class="parameter">expand</code> is <strong><code>true</code></strong>, but the libsqlite version is less
   than 3.14, an error of level <strong><code>E_WARNING</code></strong> or an <span class="classname"><a href="class.exception.html" class="classname">Exception</a></span>
   is issued, according to <span class="methodname"><a href="sqlite3.enableexceptions.html" class="methodname">SQLite3::enableExceptions()</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3stmt.getsql-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="sqlite3stmt.getsql.example.expanded">
   <p><strong>示例 #1 Inspecting the expanded SQL</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$db&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;:a,&nbsp;?,&nbsp;:c"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindValue</span><span style="color: #007700">(</span><span style="color: #DD0000">':a'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$answer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindParam</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$answer</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSQL</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
string(24) &quot;SELECT &#039;foo&#039;, &#039;42&#039;, NULL&quot;
</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>